﻿#pragma once

#ifndef RECURSIVE_BFS_MULTIPLE_CYCLE_FINDER_ALGORITHM
#define RECURSIVE_BFS_MULTIPLE_CYCLE_FINDER_ALGORITHM

/*! \file RecursiveDFSMultipleCycleFinderAlgorithm.h
	\brief Header file for RecursiveDFSMultipleCycleFinderAlgorithm class.
	
	Details.
*/

#include <vector>

#include "Graph.h"
#include "AbstractCycleFinderAlgorithm.h"

namespace analyzer {
	
	//! This class implements recursive Depth-first search (DFS) algorithm to searchimg graph.
	class RecursiveDFSMultipleCycleFinderAlgorithm : public AbstractCycleFinderAlgorithm
	{
	public:
		/*! \fn RecursiveDFSMultipleCycleFinderAlgorithm(void)
			\brief Constructor of class RecursiveDFSMultipleCycleFinderAlgorithm
		*/
		RecursiveDFSMultipleCycleFinderAlgorithm(void);
		
		/*! \fn ~RecursiveDFSMultipleCycleFinderAlgorithm(void)
			\brief Destructor of class RecursiveDFSMultipleCycleFinderAlgorithm
		*/
		~RecursiveDFSMultipleCycleFinderAlgorithm(void);

		/*! \fn bool getFailOnFirst() const
			\brief Returns the failOnFirst boolean value.
			\return Value from fail on first variable.
		*/
		bool getFailOnFirst() const;
		
		/*! \fn void setFailOnFirst(bool failOnFirst)
			\brief Sets the value responsible for stopping algorithm.
			\param failOnFirst True value makes algorithm stop.
		*/
		void setFailOnFirst(bool failOnFirst);
		
		/*! \fn virtual std::vector<std::vector<int> > findCycle(const Graph& graph)
			\brief Find a cycle in graph from argument. Overrides the analyzer::AbstractCycleFinderAlgorithm::findCycle.
			\param graph Is a graph in which the function looks for cycles.
			\return This method return the container of containers of integer values representing the cycles in the graph.
		*/
		virtual std::vector<std::vector<int> > findCycle(const Graph& graph);

	private:
		std::map<Vertex, Vertex> parentVertexMap;
		std::vector<std::vector<int> > cyclicVertices;

		void findCycleDFS(const Graph& g, Vertex u, std::vector<VertexColor>& colors);

		std::vector<int> getCyclicVertices(Vertex searchVertex, Vertex startVertex, std::map<Vertex, Vertex> parentVertex);

		bool failOnFirst;
	};
}

#endif // RECURSIVE_BFS_MULTIPLE_CYCLE_FINDER_ALGORITHM